<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ JSON.stringify(text) == '{}' ? '添加预警信息' : '修改预警信息' }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form-model ref="ruleForm" :model="form" :rules="rules">
					<a-form-model-item label="预警名称" prop="title"><a-input v-model="form.title" /></a-form-model-item>
					
					<a-form-model-item label="" class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit" :loading="loading">{{ JSON.stringify(text) == '{}' ? '确认添加' : '确认修改' }}</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-model-item>
				</a-form-model>
			</div>
		</div>
	</div>
</template>

<script>
import moment from 'moment';
import { ManageStudentCreditWarningDoSendNotice, ManageCreditWarningDoUpdate, DoGetDetailStudent,ManageStudentDoGetManageDepartList } from '@/api/follow';
export default {
	props: {
		text: Object,
		ClassList: Array,
		multipleSelection:Array
	},
	watch: {
		text: function(text) {
			if (JSON.stringify(text) == '{}') {
			} else {
				// this.GetDetailStudent(text)
				this.form = text;
				this.gradeYear = text.Grade;
			}
		}
	},
	data() {
		return {
			WarningList:this.global.WarningList,
			DepartCodeList:[],
			gradeYear: null,
			yearPickShow: false,
			gradeYear: null,
			yearPickShow: false,
			loading: false,
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			}),
			form: {
				title: '',
			},
			rules: {
				title: [
					{
						required: true,
						message: '请输入名称',
						trigger: 'change'
					}
				],
				
				
			}
		};
	},
	created() {
		// this.getOtherList()
	},
	methods: {
		filterOption(input, option) {
			return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
		},
		moment,
		handleOpenChange(status) {
			this.yearPickShow = status;
		},
		handlePanelChange(value, mode) {
			this.form.Grade = moment(value).format('YYYY');
			this.yearPickShow = false;
		},
		yearChange(date, dateString) {
			if (!date) {
				this.form.Grade = null;
			}
		},
		async getOtherList() {
			// let res = await GetClassList();
			// this.ClassList = res.data.data;
			let res1 = await ManageStudentDoGetManageDepartList();
			
			this.DepartCodeList = res1.data.data;
		},
		closeFunction(data) {
			this.$emit('closeFun', data);
			this.form = {};
			this.gradeYear = null;
			this.fileList = [];
		},
		handleSubmit(e) {
			this.$refs.ruleForm.validate(async valid => {
				if (valid) {
					this.loading = true
					let data = this.form;
					// data.EndTime = moment(this.form.EndTime).format('YYYY-MM-DD');
					// console.log(data);
					// if(data.StartDay<10){
					// 	data.StartDay='0'+data.StartDay
					// }
					let arr=[]
					if(this.multipleSelection.length>0){
						for(let i in this.multipleSelection){
							arr.push(this.multipleSelection[i].UserNo)
						}
					}
					data.userNoList=arr.toString();
					
					console.log(data);
					//return;
					let res = {};
					if (!this.text.ID) {
						res = await ManageStudentCreditWarningDoSendNotice(data);
					} else {
						res = await ManageCreditWarningDoUpdate(data);
					}
					if (res.data.code === 0) {
						this.$message.success(res.data.msg);
						this.closeFunction('1');
					} else {
						this.$message.error(res.data.msg);
					}
					this.loading = false
				} else {
					return false;
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
/deep/.ant-form-item {
	margin: 20px 50px;
}
/deep/.ant-form-item-label {
	width: 160px !important;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: right;
}
/deep/.ant-form-item-control-wrapper {
	flex: 1;
}
</style>
